package com.ruoyi.car.controller.parts;

import java.util.List;

import com.car.pojo.TbPartModuleInformation;
import com.ruoyi.car.service.parts.ITbPartModuleInformationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 电池模组信息Controller
 *
 * @author韩昊昌
 * @date 2020-06-25
 */
@Controller
@RequestMapping("/moduleInformation/information")
public class TbPartModuleInformationController extends BaseController
{
    private String prefix = "/parts/moduleInformation";

    @Autowired
    private ITbPartModuleInformationService tbPartModuleInformationService;

    @RequiresPermissions("moduleInformation:information:view")
    @GetMapping()
    public String information()
    {
        return prefix + "/information";
    }

    /**
     * 查询电池模组信息列表
     */
    @RequiresPermissions("moduleInformation:information:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbPartModuleInformation tbPartModuleInformation)
    {
        startPage();
        List<TbPartModuleInformation> list = tbPartModuleInformationService.selectTbPartModuleInformationList(tbPartModuleInformation);
        return getDataTable(list);
    }

    /**
     * 导出电池模组信息列表
     */
    @RequiresPermissions("moduleInformation:information:export")
    @Log(title = "电池模组信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbPartModuleInformation tbPartModuleInformation)
    {
        List<TbPartModuleInformation> list = tbPartModuleInformationService.selectTbPartModuleInformationList(tbPartModuleInformation);
        ExcelUtil<TbPartModuleInformation> util = new ExcelUtil<TbPartModuleInformation>(TbPartModuleInformation.class);
        return util.exportExcel(list, "information");
    }

    /**
     * 新增电池模组信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存电池模组信息
     */
    @RequiresPermissions("moduleInformation:information:add")
    @Log(title = "电池模组信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbPartModuleInformation tbPartModuleInformation)
    {
        return toAjax(tbPartModuleInformationService.insertTbPartModuleInformation(tbPartModuleInformation));
    }

    /**
     * 修改电池模组信息
     */
    @GetMapping("/edit/{moduleTypeId}")
    public String edit(@PathVariable("moduleTypeId") Long moduleTypeId, ModelMap mmap)
    {
        TbPartModuleInformation tbPartModuleInformation = tbPartModuleInformationService.selectTbPartModuleInformationById(moduleTypeId);
        mmap.put("tbPartModuleInformation", tbPartModuleInformation);
        return prefix + "/edit";
    }

    /**
     * 修改保存电池模组信息
     */
    @RequiresPermissions("moduleInformation:information:edit")
    @Log(title = "电池模组信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbPartModuleInformation tbPartModuleInformation)
    {
        return toAjax(tbPartModuleInformationService.updateTbPartModuleInformation(tbPartModuleInformation));
    }

    /**
     * 删除电池模组信息
     */
    @RequiresPermissions("moduleInformation:information:remove")
    @Log(title = "电池模组信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbPartModuleInformationService.deleteTbPartModuleInformationByIds(ids));
    }
}
